<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setting_model extends MY_Model {
    
    protected $TB_SETTING = 'dc_setting';
    protected $SETTING_COLS = array(
        'setting_key',
        'setting_val'
    );
    
    function __construct() {
        parent::__construct();
    }

    public function add_settings($setting_key, $setting_val){
        return $this->db->query("INSERT INTO $this->TB_SETTING 
            (`setting_key`, `setting_val`) VALUES 
            ('$setting_key', '$setting_val')");
    }

    public function set_setting($setting_key, $setting_val){
        return $this->db->query("UPDATE $this->TB_SETTING 
            SET `setting_val` = '$setting_val' 
            WHERE `setting_key` = '$setting_key'");
    }
    
    public function get_setting_val($setting_key) {
        $query = $this->db->query("SELECT `setting_val` FROM $this->TB_SETTING
            WHERE `setting_key` = '$setting_key' LIMIT 1");
        return $query->num_rows() ? current($query->row()) : null;
    }
    
    public function get_all_settings() {
        $query = $this->db->query("SELECT `setting_key`, `setting_val` FROM $this->TB_SETTING");
        return $query->num_rows() ? $query->result(0) : null;
    }
    
}